﻿using System.Collections.Generic;
using System.Web.Mvc;
using Mvc.RazorTools;

namespace Mvc.RazorTools.Glyphicons
{
	/// <summary>
	/// Defines the properties necessary to create a Glyphicons tag in an MVC Razor view.
	/// </summary>
	public partial class Glyphicon : MvcRazorObject
	{
		private string _iconId = string.Empty;
		private string _category = string.Empty;

		/// <summary>
		/// Initializes a new empty instance of a Mvc.RazorTools.Glyphicons.Glyphicon object. Note
		/// this empty version will not display any icon until the Id property is set.
		/// </summary>
		public Glyphicon()
		{
			this.IncludeIdInHtml = false;
		}

		/// <summary>
		/// Initializes a new instance of a Mvc.RazorTools.Glyphicons.Glyphicon object with the
		/// specified Id. The Id represents the icon name in the CSS style sheet for Glyphicons.
		/// </summary>
		/// <param name="category">The name of the set this icon is part of.</param>
		/// <param name="iconId">The CSS style sheet name of the icon this instance represents.</param>
		public Glyphicon(string category, string iconId)
			: this()
		{
			this.Category = category;
			this.IconId = iconId;
		}

		/// <summary>
		/// Gets/sets the CSS style sheet name of the icon this instance represents. 
		/// If the object is a predefined object then this value cannot be changed. 
		/// Read-only if this instanced is locked.
		/// </summary>
		public string IconId
		{
			get
			{
				return _iconId;
			}
			set
			{
				if (!this.Locked)
				{
					_iconId = value;
					this.UpdateClassAttribute("Id", _iconId);
				}
				else
				{
					throw new ModifyLockedInstanceException();
				}
			}
		}

		/// <summary>
		/// Gets/sets the set that this icon is part of.
		/// </summary>
		public string Category
		{
			get
			{
				return _category;
			}
			set
			{
				if (!this.Locked)
				{
					_category = value;
				}
				else
				{
					throw new ModifyLockedInstanceException();
				}
			}
		}

		/// <summary>
		/// Initializes and returns a new instance of a Mvc.RazorTools.Glyphicons.Glyphicon object
		/// with the specified Id.
		/// </summary>
		/// <param name="category">The name of the set this icon is part of.</param>
		/// <param name="iconId">The CSS style sheet name of the icon this instance represents.</param>
		/// <returns>A newly initialized Mvc.RazorTools.Glyphicons.Glyphicon object.</returns>
		public static Glyphicon Create(string category, string iconId)
		{
			return new Glyphicon() { Category = category, IconId = iconId };
		}

		/// <summary>
		/// Initializes and returns a new instance of a Mvc.RazorTools.Glyphicons.Glyphicon object
		/// with the specified Id, and name.
		/// </summary>
		/// <param name="category">The name of the set this icon is part of.</param>
		/// <param name="iconId">The CSS style sheet name of the icon this instance represents.</param>
		/// <param name="name">A System.String that contains the name of this instance.</param>
		/// <returns>A newly initialized Mvc.RazorTools.Glyphicons.Glyphicon object.</returns>
		internal static Glyphicon Create(string category, string iconId, string name)
		{
			return new Glyphicon() { Category = category, IconId = iconId, Name = name };
		}

		/// <summary>
		/// Initializes and returns a new instance of a Mvc.RazorTools.Glyphicons.Glyphicon object
		/// with the specified Id, name and whether or not this instance is locked.
		/// </summary>
		/// <param name="category">The name of the set this icon is part of.</param>
		/// <param name="iconId">The CSS style sheet name of the icon this instance represents.</param>
		/// <param name="name">A System.String that contains the name of this instance.</param>
		/// <param name="locked">A value that indicates if the properties on this instance are locked or not.</param>
		/// <returns>A newly initialized Mvc.RazorTools.Glyphicons.Glyphicon object.</returns>
		internal static Glyphicon Create(string category, string iconId, string name, bool locked)
		{
			return new Glyphicon() { Category = category, IconId = iconId, Name = name, Locked = locked };
		}

		/// <summary>
		/// Initializes and returns a new instance of a Mvc.RazorTools.Glyphicons.Glyphicon object
		/// with the specified Id and custom class attributes.
		/// </summary>
		/// <param name="category">The name of the set this icon is part of.</param>
		/// <param name="iconId">The CSS style sheet name of the icon this instance represents.</param>
		/// <param name="classAttributes">A list of custom class attributes for this instance.</param>
		/// <returns>A newly initialized Mvc.RazorTools.Glyphicons.Glyphicon object.</returns>
		public static Glyphicon Create(string category, string iconId, IDictionary<string, string> classAttributes)
		{
			Glyphicon returnValue = new Glyphicon(category, iconId);

			returnValue.MergeClassAttributes(classAttributes);

			return returnValue;
		}

		/// <summary>
		/// Converts this instance of the Mvc.RazorTools.Glyphicons.Glyphicon
		/// to a System.Web.Mvc.MvcHtmlString object containing the HTML markup 
		/// for the icon.
		/// </summary>
		/// <param name="item">The Mvc.RazorTools.Glyphicons.Glyphicon instance to be converted.</param>
		/// <returns>A System.Web.Mvc.MvcHtmlString object containing the HTML markup for this Glyphicons icon.</returns>
		public static implicit operator MvcHtmlString(Glyphicon item)
		{
			return item.Html;
		}

		/// <summary>
		/// Converts this instance of the Mvc.RazorTools.Glyphicons.Glyphicon
		/// to an System.String object containing the HTML markup for the icon.
		/// </summary>
		/// <param name="item">The Mvc.RazorTools.Glyphicons.Glyphicon instance to be converted.</param>
		/// <returns>A System.String object containing the HTML markup for this Glyphicons icon.</returns>
		public static implicit operator string(Glyphicon item)
		{
			return item.Html.ToString();
		}

		protected override string OnInitializeHtmlTag()
		{
			return "i";
		}

		protected override object OnClone()
		{
			Glyphicon returnValue = Glyphicon.Create(this.Category, this.IconId, this.Name, false);
			returnValue.MergeClassAttributes(this.ClassAttributes);
			return returnValue;
		}

		protected override string OnInitializeName()
		{
			return this.IconId;
		}
	}
}